package cc.rengu.igas.bsps.core.service.trans;

import cc.rengu.igas.acct.facade.base.BaseRequest;
import cc.rengu.igas.bomp.facade.request.UserInfoQueryRequest;
import cc.rengu.igas.bomp.facade.response.UserInfoQueryResponse;
import cc.rengu.igas.bsps.common.constant.BspsAppParamConstant;
import cc.rengu.igas.bsps.common.constant.BspsTreeNodeConstant;
import cc.rengu.igas.bsps.common.dao.UserOrderInfoMapper;
import cc.rengu.igas.bsps.common.dao.impl.UserOrderInfoMapperImpl;
import cc.rengu.igas.bsps.common.entity.UserOrderInfo;
import cc.rengu.igas.bsps.common.enums.RespCodeEnum;
import cc.rengu.igas.bsps.core.model.UserSessionInfo;
import cc.rengu.igas.bsps.core.service.base.ManageService;
import cc.rengu.igas.bsps.facade.bean.UserOrderInfoBean;
import cc.rengu.igas.bsps.facade.request.ScanQrCodeReceiptsRequest;
import cc.rengu.igas.bsps.facade.request.UserOrderInfoRequest;
import cc.rengu.igas.bsps.facade.response.TransInfoQueryResponse;
import cc.rengu.igas.bsps.facade.response.UserOrderInfoResponse;
import cc.rengu.jradp.dubbo.service.BaseService;
import cc.rengu.jradp.packetswitch.IncomingPackSwitchImpl;
import cc.rengu.jradp.packetswitch.OutgoingPackSwitchImpl;
import cc.rengu.oltp.service.base.BizBaseService;
import cc.rengu.oltp.service.common.constant.AppParamConstant;
import cc.rengu.oltp.service.common.constant.TreeNodeConstant;
import cc.rengu.oltp.service.common.dao.MchntOrderInfoMapper;
import cc.rengu.oltp.service.common.dao.PayOrderInfoMapper;
import cc.rengu.oltp.service.common.dao.impl.MchntOrderInfoMapperImpl;
import cc.rengu.oltp.service.common.dao.impl.PayOrderInfoMapperImpl;
import cc.rengu.oltp.service.common.entity.MchntOrderInfo;
import cc.rengu.oltp.service.common.entity.PayOrderInfo;
import cc.rengu.oltp.service.common.entity.SysParam;
import cc.rengu.oltp.service.common.enums.ChannelEnum;
import cc.rengu.oltp.service.model.BizException;
import cc.rengu.oltp.service.model.BizResponse;
import cc.rengu.oltp.service.model.RiskMonitorInfo;
import cc.rengu.oltp.service.model.TxnInfo;
import cc.rengu.oltp.service.realize.SysParamService;
import cc.rengu.oltp.service.realize.TxnInfoService;
import cc.rengu.oltp.service.realize.impl.SysParamServiceImpl;
import cc.rengu.oltp.service.realize.impl.TxnInfoServiceImpl;
import cc.rengu.oltp.utility.util.*;
import cc.rengu.utility.log.RgLog;
import cc.rengu.utility.log.RgLogger;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.Feature;
import org.apache.commons.codec.binary.Base64;

import java.io.File;
import java.io.FileInputStream;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class UserOrderInfoService extends ManageService {

    @Override
    protected Object bizBeforeCust() throws Exception {
        UserOrderInfoRequest userOrderInfoRequest = new UserOrderInfoRequest();
        ConvertUtil.convertOutput(userOrderInfoRequest);
        return userOrderInfoRequest;
    }

    @Override
    protected BizResponse bizProcessCust(Object request) throws Exception {
        UserOrderInfoRequest userOrderInfoRequest = (UserOrderInfoRequest) request;
        UserOrderInfoMapper userOrderInfoMapper = new UserOrderInfoMapperImpl();
        BizResponse bizResponse = new BizResponse();
        UserOrderInfoResponse response = new UserOrderInfoResponse();
        UserOrderInfo uoi=new UserOrderInfo();

        if (null!=userOrderInfoRequest.getUserOrderId() && !userOrderInfoRequest.getUserOrderId().isEmpty()&&null!=userOrderInfoRequest.getInstId()&&!userOrderInfoRequest.getInstId().isEmpty()){
            uoi.setUserOrderId(userOrderInfoRequest.getUserOrderId());
            uoi.setInstId(userOrderInfoRequest.getInstId());
        }
        UserOrderInfo userOrderInfos = userOrderInfoMapper.userOrderInfoList(uoi);
        response.setHeader(userOrderInfoRequest.getHeader());
            UserOrderInfoBean userOrderInfoBean = new UserOrderInfoBean();
            BeanUtil.beanCopy(userOrderInfos, userOrderInfoBean);
            response.setUserOrderInfoBean(userOrderInfoBean);
        bizResponse.setResult(response);
        bizResponse.setRspSysId(AppParamConstant.SYS_ID);
        bizResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
        bizResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());
        return bizResponse;
    }

    @Override
    protected void bizAfterCust(Object response) throws Exception {
        BizResponse bizResponse = (BizResponse) response;
        UserOrderInfoResponse userOrderInfoResponse = (UserOrderInfoResponse) bizResponse.getResult();
        ConvertUtil.convertInput(userOrderInfoResponse);
    }

}